home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / shells / sh03bin.zoo / sh-pl03 / sh / sh.1 < prev    next >
Encoding:
Text File  |  1993-02-16  |  38.1 KB  |  859 lines

  1.  
  2.  
  3.  
  4.    March 7, 1991                                                        SH(1)
  5.  
  6.  
  7.  
  8.    NAME
  9.      ash - a shell
  10.  
  11.    SYNOPSIS
  12.      ash [ -efIijnsxz ] [ +efIijnsxz ] [ -c _✓c_✓o_✓m_✓m_✓a_✓n_✓d ] [ _✓a_✓r_✓g ] ...
  13.  
  14.    COPYRIGHT
  15.      Copyright 1989 by Kenneth Almquist.
  16.  
  17.    DESCRIPTION
  18.      _✓A_✓s_✓h is a version of _✓s_✓h with features similar to those of the System V
  19.      shell.  This manual page lists all the features of _✓a_✓s_✓h but concentrates
  20.      on the ones not in other shells.
  21.  
  22.    Invocation
  23.  
  24.      If the -c options is given, then the shell executes the specified shell
  25.      command.  The -s flag cause the shell to read commands from the standard
  26.      input (after executing any command specified with the -c option.  If
  27.      neither the -s or -c options are set, then the first _✓a_✓r_✓g is taken as the
  28.      name of a file to read commands from.  If this is impossible because
  29.      there are no arguments following the options, then _✓a_✓s_✓h will set the -s
  30.      flag and will read commands from the standard input.
  31.  
  32.      The shell sets the initial value of the positional parameters from the
  33.      _✓a_✓r_✓gs remaining after any _✓a_✓r_✓g used as the name of a file of commands is
  34.      deleted.
  35.  
  36.      The flags (other than -c) are set by preceding them with ``-'' and
  37.      cleared by preceding them with ``+''; see the _✓s_✓e_✓t builtin command for a
  38.      list of flags.  If no value is specified for the -i flag, the -s flag is
  39.      set, and the standard input and output of the shell are connected to
  40.      terminals, then the -i flag will be set.  If no value is specified for
  41.      the -j flag, then the -j flag will be set if the -i flag is set.
  42.  
  43.      When the shell is invoked with the -c option, it is good practice to
  44.      include the -_✓i flag if the command was entered interactively by a user.
  45.      For compatibility with the System V shell, the -_✓i option should come
  46.      after the -c option.
  47.  
  48.      If the first character of argument zero to the shell is ``-'', the shell
  49.      is assumed to be a login shell, and the files /etc/profile and .profile
  50.      are read if they exist.  If the environment variable SHINIT is set on
  51.      entry to the shell, the commands in SHINIT are normally parsed and exe-
  52.      cuted.  SHINIT is not examined if the shell is a login shell, or if it
  53.      the shell is running a shell procedure.   (A shell is considered to be
  54.      running a shell procedure if neither the -s nor the -c options are set.)
  55.  
  56.    Control Structures
  57.  
  58.      A _✓l_✓i_✓s_✓t is a sequence of zero or more commands separated by newlines,
  59.      semicolons, or ampersands, and optionally terminated by one of these
  60.      three characters.  (This differs from the System V shell, which requires
  61.      a list to contain at least one command in most cases.)  The commands in
  62.      a list are executed in the order they are written.  If command is fol-
  63.      lowed by an ampersand, the shell starts the command and immediately
  64.      proceed onto the next command; otherwise it waits for the command to
  65.      terminate before proceeding to the next one.
  66.  
  67.      ``&&'' and ``||'' are binary operators.  ``&&'' executes the first com-
  68.      mand, and then executes the second command iff the exit status of the
  69.      first command is zero.  ``||'' is similar, but executes the second com-
  70.      mand iff the exit status of the first command is nonzero.  ``&&'' and
  71.      ``||'' both have the same priority.
  72.  
  73.      The ``|'' operator is a binary operator which feeds the standard output
  74.      of the first command into the standard input of the second command.  The
  75.      exit status of the ``|'' operator is the exit status of the second com-
  76.      mand.  ``|'' has a higher priority than ``||'' or ``&&''.
  77.  
  78.      An _✓i_✓f command looks like
  79.  
  80.          if list
  81.          then list
  82.        [ elif list
  83.            then    list ] ...
  84.        [ else    list ]
  85.          fi
  86.  
  87.  
  88.      A _✓w_✓h_✓i_✓l_✓e command looks like
  89.  
  90.          while list
  91.          do   list
  92.          done
  93.  
  94.      The two lists are executed repeatedly while the exit status of the first
  95.      list is zero.  The _✓u_✓n_✓t_✓i_✓l command is similar, but has the word until in
  96.      place of while
  97.       repeats until the exit status of the first list is zero.
  98.  
  99.      The _✓f_✓o_✓r command looks like
  100.  
  101.          for variable in word...
  102.          do   list
  103.          done
  104.  
  105.      The words are expanded, and then the list is executed repeatedly with
  106.      the variable set to each word in turn.  do and done may be replaced with
  107.      ``{'' and ``}''.
  108.  
  109.      The _✓b_✓r_✓e_✓a_✓k and _✓c_✓o_✓n_✓t_✓i_✓n_✓u_✓e commands look like
  110.  
  111.          break [ num ]
  112.          continue [ num ]
  113.  
  114.      _✓B_✓r_✓e_✓a_✓k terminates the _✓n_✓u_✓m innermost _✓f_✓o_✓r or _✓w_✓h_✓i_✓l_✓e loops.  _✓C_✓o_✓n_✓t_✓i_✓n_✓u_✓e contin-
  115.      ues with the next iteration of the _✓n_✓u_✓m'_✓t_✓h innermost loop.  These are
  116.      implemented as builtin commands.
  117.  
  118.      The _✓c_✓a_✓s_✓e command looks like
  119.  
  120.          case word in
  121.          pattern) list ;;
  122.          ...
  123.          esac
  124.  
  125.      The pattern can actually be one or more patterns (see _✓P_✓a_✓t_✓t_✓e_✓r_✓n_✓s below),
  126.      separated by ``|'' characters.
  127.  
  128.      Commands may be grouped by writing either
  129.  
  130.          (list)
  131.  
  132.      or
  133.  
  134.          { list; }
  135.  
  136.      The first of these executes the commands in a subshell.
  137.  
  138.      A function definition looks like
  139.  
  140.          name ( ) command
  141.  
  142.      A function definition is an executable statement; when executed it
  143.      installs a function named name and returns an exit status of zero.  The
  144.      command is normally a list enclosed between ``{'' and ``}''.
  145.  
  146.      Variables may be declared to be local to a function by using a _✓l_✓o_✓c_✓a_✓l
  147.      command.  This should appear as the first staement of a function, and
  148.      looks like
  149.  
  150.          local [ variable | - ] ...
  151.  
  152.      _✓L_✓o_✓c_✓a_✓l is implemented as a builtin command.
  153.  
  154.      When a variable is made local, it inherits the initial value and
  155.      exported and readonly flags from the variable with the same name in the
  156.      surrounding scope, if there is one.  Otherwise, the variable is ini-
  157.      tially unset.  _✓A_✓s_✓h uses dynamic scoping, so that if you make the vari-
  158.      able x local to function _✓f, which then calls function _✓g, references to
  159.      the variable x made inside _✓g will refer to the variable x declared
  160.      inside _✓f, not to the global variable named x.
  161.  
  162.      The only special parameter than can be made local is ``-''.  Making ``-
  163.      '' local any shell options that are changed via the _✓s_✓e_✓t command inside
  164.      the function to be restored to their original values when the function
  165.      returns.
  166.  
  167.      The _✓r_✓e_✓t_✓u_✓r_✓n command looks like
  168.  
  169.          return [ exitstatus ]
  170.  
  171.      It terminates the currently executing function.  _✓R_✓e_✓t_✓u_✓r_✓n is implemented
  172.      as a builtin command.
  173.  
  174.    Simple Commands
  175.  
  176.      A simple command is a sequence of words.  The execution of a simple com-
  177.      mand proceeds as follows.  First, the leading words of the form
  178.      ``name=value'' are stripped off and assigned to the environment of the
  179.      command.  Second, the words are expanded.  Third, the first remaining
  180.      word is taken as the command name that command is located.  Fourth, any
  181.      redirections are performed.  Fifth, the command is executed.  We look at
  182.      these operations in reverse order.
  183.  
  184.      The execution of the command varies with the type of command.  There are
  185.      three types of commands:  shell functions, builtin commands, and normal
  186.      programs.
  187.  
  188.      When a shell function is executed, all of the shell positional parame-
  189.      ters (except $0, which remains unchanged) are set to the parameters to
  190.      the shell function.  The variables which are explicitly placed in the
  191.      environment of the command (by placing assignments to them before the
  192.      function name) are made local to the function and are set to values
  193.      given.  Then the command given in the function definition is executed.
  194.      The positional parameters are restored to their original values when the
  195.      command completes.
  196.  
  197.      Shell builtins are executed internally to the shell, without spawning a
  198.      new process.
  199.  
  200.      When a normal program is executed, the shell runs the program, passing
  201.      the parameters and the environment to the program.  If the program is a
  202.      shell procedure, the shell will interpret the program in a subshell.
  203.      The shell will reinitialize itself in this case, so that the effect will
  204.      be as if a new shell had been invoked to handle the shell procedure,
  205.      except that the location of commands located in the parent shell will be
  206.      remembered by the child.  If the program is a file beginning with
  207.      ``#!'', the remainder of the first line specifies an interpreter for the
  208.      program.  The shell (or the operating system, under Berkeley UNIX) will
  209.      run the interpreter in this case.  The arguments to the interpreter will
  210.      consist of any arguments given on the first line of the program, fol-
  211.      lowed by the name of the program, followed by the arguments passed to
  212.      the program.
  213.  
  214.    Redirection
  215.  
  216.      Input/output redirections can be intermixed with the words in a simple
  217.      command and can be placed following any of the other commands.  When
  218.      redirection occurs, the shell saves the old values of the file descrip-
  219.      tors and restores them when the command completes.  The ``<'', ``>'',
  220.      and ``>>'' redirections open a file for input, output, and appending,
  221.      respectively.  The ``<&digit'' and ``>&digit'' makes the input or output
  222.      a duplicate of the file descriptor numbered by the digit.  If a minus
  223.      sign is used in place of a digit, the standard input or standard output
  224.      are closed.
  225.  
  226.      The ``<< word'' redirection takes input from a _✓h_✓e_✓r_✓e document.  As the
  227.      shell encounters ``<<'' redirections, it collects them.  The next time
  228.      it encounters an unescaped newline, it reads the documents in turn.  The
  229.      word following the ``<<'' specifies the contents of the line that ter-
  230.      minates the document.  If none of the quoting methods ('', "", or \) are
  231.      used to enter the word, then the document is treated like a word inside
  232.      double quotes:  ``$'' and backquote are expanded and backslash can be
  233.      used to escape these and to continue long lines.  The word cannot con-
  234.      tain any variable or command substitutions, and its length (after quot-
  235.      ing) must be in the range of 1 to 79 characters.  If ``<<-'' is used in
  236.      place of ``<<'', then leading tabs are deleted from the lines of the
  237.      document.  (This is to allow you do indent shell procedures containing
  238.      here documents in a natural fashion.)
  239.  
  240.      Any of the preceding redirection operators may be preceded by a single
  241.      digit specifying the file descriptor to be redirected.  There cannot be
  242.      any white space between the digit and the redirection operator.
  243.  
  244.    Path Search
  245.  
  246.      When locating a command, the shell first looks to see if it has a shell
  247.      function by that name.  Then, if PATH does not contain an entry for
  248.      "%builtin", it looks for a builtin command by that name.  Finally, it
  249.      searches each entry in PATH in turn for the command.
  250.  
  251.      The value of the PATH variable should be a series of entries separated
  252.      by colons.  Each entry consists of a directory name, or a directory name
  253.      followed by a flag beginning with a percent sign.  The current directory
  254.      should be indicated by an empty directory name.
  255.  
  256.      If no percent sign is present, then the entry causes the shell to search
  257.      for the command in the specified directory.  If the flag is ``%builtin''
  258.      then the list of shell builtin commands is searched.  If the flag is
  259.      ``%func'' then the directory is searched for a file which is read as
  260.      input to the shell.  This file should define a function whose name is
  261.      the name of the command being searched for.
  262.  
  263.      Command names containing a slash are simply executed without performing
  264.      any of the above searches.
  265.  
  266.    The Environment
  267.  
  268.      The environment of a command is a set of name/value pairs.  When the
  269.      shell is invoked, it reads these names and values, sets the shell vari-
  270.      ables with these names to the corresponding values, and marks the vari-
  271.      ables as exported.  The _✓e_✓x_✓p_✓o_✓r_✓t command can be used to mark additional
  272.      variables as exported.
  273.  
  274.      The environment of a command is constructed by constructing name/value
  275.      pairs from all the exported shell variables, and then modifying this set
  276.      by the assignments which precede the command, if any.
  277.  
  278.    Expansion
  279.  
  280.      The process of evaluating words when a shell procedure is executed is
  281.      called _✓e_✓x_✓p_✓a_✓n_✓s_✓i_✓o_✓n.  Expansion consists of four steps:  variable substitu-
  282.      tion, command substitution, word splitting, and file name generation.
  283.      If a word is the expression following the word case in a case statement,
  284.      the file name which follows a redirection symbol, or an assignment to
  285.      the environment of a command, then the word cannot be split into multi-
  286.      ple words.  In these cases, the last two steps of the expansion process
  287.      are omitted.
  288.  
  289.    Variable Substitution
  290.  
  291.      To be written.
  292.  
  293.    Command Substitution
  294.  
  295.      _✓A_✓s_✓h accepts two syntaxes for command substitution:
  296.  
  297.      `_✓l_✓i_✓s_✓t`
  298.  
  299.       and
  300.  
  301.      $(_✓l_✓i_✓s_✓t)
  302.  
  303.       Either of these may be included in a word.  During the command substi-
  304.       tution process, the command (syntactly a _✓l_✓i_✓s_✓t) will be executed and
  305.       anything that the command writes to the standard output will be cap-
  306.       tured by the shell.  The final newline (if any) of the output will be
  307.       deleted; the rest of the output will be substituted for the command in
  308.       the word.
  309.  
  310.    Word Splitting
  311.  
  312.      When the value of a variable or the output of a command is substituted,
  313.      the resulting text is subject to word splitting, unless the dollar sign
  314.      introducing the variable or backquotes containing the text were enclosed
  315.      in double quotes.  In addition, ``$@'' is subject to a special type of
  316.      splitting, even in the presence of double quotes.
  317.  
  318.      Ash uses two different splitting algorithms.  The normal approach, which
  319.      is intended for splitting text separated by which space, is used if the
  320.      first character of the shell variable IFS is a space.  Otherwise an
  321.      alternative experimental algorithm, which is useful for splitting (pos-
  322.      sibly empty) fields separated by a separator character, is used.
  323.  
  324.  
  325.      When performing splitting, the shell scans the replacement text looking
  326.      for a character (when IFS does not begin with a space) or a sequence of
  327.      characters (when IFS does begin with a space), deletes the character or
  328.      sequence of characters, and spits the word into two strings at that
  329.      point.  When IFS begins with a space, the shell deletes either of the
  330.      strings if they are null.  As a special case, if the word containing the
  331.      replacement text is the null string, the word is deleted.
  332.  
  333.      The variable ``$@'' is special in two ways.  First, splitting takes
  334.      place between the positional parameters, even if the text is enclosed in
  335.      double quotes.  Second, if the word containing the replacement text is
  336.      the null string and there are no positional parameters, then the word is
  337.      deleted.  The result of these rules is that "$@" is equivalent to "$1"
  338.      "$2" ... "$_✓n", where _✓n is the number of positional parameters.  (Note
  339.      that this differs from the System V shell.  The System V documentation
  340.      claims that "$@" behaves this way; in fact on the System V shell "$@" is
  341.      equivalent to "" when there are no positional paramteters.)
  342.  
  343.    File Name Generation
  344.  
  345.      Unless the -f flag is set, file name generation is performed after word
  346.      splitting is complete.  Each word is viewed as a series of patterns,
  347.      separated by slashes.  The process of expansion replaces the word with
  348.      the names of all existing files whose names can be formed by replacing
  349.      each pattern with a string that matches the specified pattern.  There
  350.      are two restrictions on this:  first, a pattern cannot match a string
  351.      containing a slash, and second, a pattern cannot match a string starting
  352.      with a period unless the first character of the pattern is a period.
  353.  
  354.      If a word fails to match any files and the -z flag is not set, then the
  355.      word will be left unchanged (except that the meta-characters will be
  356.      converted to normal characters).  If the -z flag is set, then the word
  357.      is only left unchanged if none of the patterns contain a character that
  358.      can match anything besides itself.  Otherwise the -z flag forces the
  359.      word to be replaced with the names of the files that it matches, even if
  360.      there are zero names.
  361.  
  362.    Patterns
  363.  
  364.      A _✓p_✓a_✓t_✓t_✓e_✓r_✓n consists of normal characters, which match themselves, and
  365.      meta-characters.  The meta-characters are ``!'', ``*'', ``?'', and
  366.      ``[''.  These characters lose there special meanings if they are quoted.
  367.      When command or variable substitution is performed and the dollar sign
  368.      or back quotes are not double quoted, the value of the variable or the
  369.      output of the command is scanned for these characters and they are
  370.      turned into meta-characters.
  371.  
  372.      Two exclamation points at the beginning of a pattern function as a
  373.      ``not'' operator, causing the pattern to match any string that the
  374.      remainder of the pattern does _✓n_✓o_✓t match.  Other occurances of exclama-
  375.      tion points in a pattern match exclamation points.  Two exclamation
  376.      points are required rather than one to decrease the incompatibility with
  377.      the System V shell (which does not treat exclamation points specially).
  378.  
  379.      An asterisk (``*'') matches any string of characters.  A question mark
  380.      matches any single character.  A left bracket (``['') introduces a char-
  381.      acter class.  The end of the character class is indicated by a ``]''; if
  382.      the ``]'' is missing then the ``['' matches a ``['' rather than intro-
  383.      ducing a character class.  A character class matches any of the charac-
  384.      ters between the square brackets.  A range of characters may be speci-
  385.      fied using a minus sign.  The character class may be complemented by
  386.      making an exclamation point the first character of the character class.
  387.  
  388.      To include a ``]'' in a character class, make it the first character
  389.      listed (after the ``!'', if any).  To include a minus sign, make it the
  390.      first or last character listed.
  391.  
  392.    The /u Directory
  393.  
  394.      By convention, the name ``/u/user'' refers to the home directory of the
  395.      specified user.  There are good reasons why this feature should be sup-
  396.      ported by the file system (using a feature such as symbolic links)
  397.      rather than by the shell, but _✓a_✓s_✓h is capable of performing this mapping
  398.      if the file system doesn't.  If the mapping is done by _✓a_✓s_✓h, setting the
  399.      -f flag will turn it off.
  400.  
  401.    Character Set
  402.  
  403.      _✓A_✓s_✓h silently discards nul characters.  Any other character will be han-
  404.      dled correctly by _✓a_✓s_✓h, including characters with the high order bit set.
  405.  
  406.    Job Names and Job Control
  407.  
  408.      The term _✓j_✓o_✓b refers to a process created by a shell command, or in the
  409.      case of a pipeline, to the set of processes in the pipeline.  The ways
  410.      to refer to a job are:
  411.  
  412.      %_✓n_✓u_✓m_✓b_✓e_✓r %_✓s_✓t_✓r_✓i_✓n_✓g %% _✓p_✓r_✓o_✓c_✓e_✓s_✓s__✓i_✓d
  413.  
  414.       The first form identifies a job by job number.  When a command is run,
  415.       _✓a_✓s_✓h assigns it a job number (the lowest unused number is assigned).
  416.       The second form identifies a job by giving a prefix of the command used
  417.       to create the job.  The prefix must be unique.  If there is only one
  418.       job, then the null prefix will identify the job, so you can refer to
  419.       the job by writing ``%''.  The third form refers to the _✓c_✓u_✓r_✓r_✓e_✓n_✓t _✓j_✓o_✓b.
  420.       The current job is the last job to be stopped while it was in the fore-
  421.       ground.  (See the next paragraph.)  The last form identifies a job by
  422.       giving the process id of the last process in the job.
  423.  
  424.      If the operating system that _✓a_✓s_✓h is running on supports job control, _✓a_✓s_✓h
  425.      will allow you to use it.  In this case, typing the suspend character
  426.      (typically ^Z) while running a command will return you to _✓a_✓s_✓h and will
  427.      make the suspended command the current job.  You can then continue the
  428.      job in the background by typing _✓b_✓g, or you can continue it in the fore-
  429.      ground by typing _✓f_✓g.
  430.  
  431.    Atty
  432.  
  433.      If the shell variable ATTY is set, and the shell variable TERM is not
  434.      set to ``emacs'', then _✓a_✓s_✓h generates appropriate escape sequences to
  435.      talk to _✓a_✓t_✓t_✓y(1).
  436.  
  437.    Exit Statuses
  438.  
  439.      By tradition, an exit status of zero means that a command has succeeded
  440.      and a nonzero exit status indicates that the command failed.  This is
  441.      better than no convention at all, but in practice it is extremely useful
  442.      to allow commands that succeed to use the exit status to return informa-
  443.      tion to the caller.  A variety of better conventions have been proposed,
  444.      but none of them has met with universal approval.  The convention used
  445.      by _✓a_✓s_✓h and all the programs included in the _✓a_✓s_✓h distribution is as fol-
  446.      lows:
  447.                0         Success.
  448.                1         Alternate success.
  449.                2         Failure.
  450.                129-...   Command terminated by a signal.
  451.      The _✓a_✓l_✓t_✓e_✓r_✓n_✓a_✓t_✓e _✓s_✓u_✓c_✓c_✓e_✓s_✓s return is used by commands to indicate various
  452.      conditions which are not errors but which can, with a little imagina-
  453.      tion, be conceived of as less successful than plain success.  For exam-
  454.      ple, _✓t_✓e_✓s_✓t returns 1 when the tested condition is false and _✓g_✓e_✓t_✓o_✓p_✓t_✓s
  455.      returns 1 when there are no more options.  Because this convention is
  456.      not used universally, the -e option of _✓a_✓s_✓h causes the shell to exit when
  457.      a command returns 1 even though that contradicts the convention
  458.      described here.
  459.  
  460.      When a command is terminated by a signal, the uses 128 plus the signal
  461.      number as the exit code for the command.
  462.  
  463.    Builtin Commands
  464.  
  465.      This concluding section lists the builtin commands which are builtin
  466.      because they need to perform some operation that can't be performed by a
  467.      separate process.  In addition to these, there are several other com-
  468.      mands (_✓c_✓a_✓t_✓f, _✓e_✓c_✓h_✓o, _✓e_✓x_✓p_✓r, _✓l_✓i_✓n_✓e, _✓n_✓l_✓e_✓c_✓h_✓o, _✓t_✓e_✓s_✓t, ``:'', and _✓t_✓r_✓u_✓e) which can
  469.      optionally be compiled into the shell.  The builtin commands described
  470.      below that accept options use the System V Release 2 _✓g_✓e_✓t_✓o_✓p_✓t(3) syntax.
  471.  
  472.  
  473.      bg [ _✓j_✓o_✓b ] ...
  474.           Continue the specified jobs (or the current job if no jobs are
  475.           given) in the background.  This command is only available on sys-
  476.           tems with Bekeley job control.
  477.  
  478.      bltin _✓c_✓o_✓m_✓m_✓a_✓n_✓d _✓a_✓r_✓g...
  479.           Execute the specified builtin command.  (This is useful when you
  480.           have a shell function with the same name as a builtin command.)
  481.  
  482.      cd [ _✓d_✓i_✓r_✓e_✓c_✓t_✓o_✓r_✓y ]
  483.           Switch to the specified directory (default $HOME).  If the an entry
  484.           for CDPATH appears in the environment of the cd command or the
  485.           shell variable CDPATH is set and the directory name does not begin
  486.           with a slash, then the directories listed in CDPATH will be
  487.           searched for the specified directory.  The format of CDPATH is the
  488.           same as that of PATH.  In an interactive shell, the cd command will
  489.           print out the name of the directory that it actually switched to if
  490.           this is different from the name that the user gave.  These may be
  491.           different either because the CDPATH mechanism was used or because a
  492.           symbolic link was crossed.
  493.  
  494.      . _✓f_✓i_✓l_✓e
  495.           The commands in the specified file are read and executed by the
  496.           shell.  A path search is not done to find the file because the
  497.           directories in PATH generally contain files that are intended to be
  498.           executed, not read.
  499.  
  500.      eval _✓s_✓t_✓r_✓i_✓n_✓g...
  501.           The strings are parsed as shell commands and executed.  (This
  502.           differs from the System V shell, which concatenates the arguments
  503.           (separated by spaces) and parses the result as a single command.)
  504.  
  505.      exec [ _✓c_✓o_✓m_✓m_✓a_✓n_✓d _✓a_✓r_✓g...  ]
  506.           Unless _✓c_✓o_✓m_✓m_✓a_✓n_✓d is omitted, the shell process is replaced with the
  507.           specified program (which must be a real program, not a shell buil-
  508.           tin or function).  Any redirections on the exec command are marked
  509.           as permanent, so that they are not undone when the exec command
  510.           finishes.  If the command is not found, the exec command causes the
  511.           shell to exit.
  512.  
  513.      exit [ _✓e_✓x_✓i_✓t_✓s_✓t_✓a_✓t_✓u_✓s ]
  514.           Terminate the shell process.  If _✓e_✓x_✓i_✓t_✓s_✓t_✓a_✓t_✓u_✓s is given it is used as
  515.           the exit status of the shell; otherwise the exit status of the
  516.           preceding command is used.
  517.  
  518.      export _✓n_✓a_✓m_✓e...
  519.           The specified names are exported so that they will appear in the
  520.           environment of subsequent commands.  The only way to un-export a
  521.           variable is to unset it.  _✓A_✓s_✓h allows the value of a variable to be
  522.           set at the same time it is exported by writing
  523.  
  524.               export name=value
  525.  
  526.           With no arguments the export command lists the names of all
  527.           exported variables.
  528.  
  529.      fg [ _✓j_✓o_✓b ]
  530.           Move the specified job or the current job to the foreground.  This
  531.           command is only available on systems with Bekeley job control.
  532.  
  533.      getopts _✓o_✓p_✓t_✓s_✓t_✓r_✓i_✓n_✓g _✓v_✓a_✓r
  534.           The System V _✓g_✓e_✓t_✓o_✓p_✓t_✓s command.
  535.  
  536.      hash -rv _✓c_✓o_✓m_✓m_✓a_✓n_✓d...
  537.           The shell maintains a hash table which remembers the locations of
  538.           commands.  With no arguments whatsoever, the hash command prints
  539.           out the contents of this table.  Entries which have not been looked
  540.           at since the last _✓c_✓d command are marked with an asterisk; it is
  541.           possible for these entries to be invalid.
  542.  
  543.           With arguments, the hash command removes the specified commands
  544.           from the hash table (unless they are functions) and then locates
  545.           them.  With the -v option, _✓h_✓a_✓s_✓h prints the locations of the com-
  546.           mands as it finds them.  The -r option causes the _✓h_✓a_✓s_✓h command to
  547.           delete all the entries in the hash table except for functions.
  548.  
  549.      jobid [ _✓j_✓o_✓b ]
  550.           Print the process id's of the processes in the job.  If the job
  551.           argument is omitted, use the current job.
  552.  
  553.      jobs
  554.           This command lists out all the background processes which are chil-
  555.           dren of the current shell process.
  556.  
  557.      lc [ _✓f_✓u_✓n_✓c_✓t_✓i_✓o_✓n-_✓n_✓a_✓m_✓e ]
  558.           The function name is defined to execute the last command entered.
  559.           If the function name is omitted, the last command executed is exe-
  560.           cuted again.  This command only works if the -i flag is set.
  561.  
  562.      pwd
  563.           Print the current directory.  The builtin command may differ from
  564.           the program of the same name because the builtin command remembers
  565.           what the current directory is rather than recomputing it each time.
  566.           This makes it faster.  However, if the current directory is
  567.           renamed, the builtin version of pwd will continue to print the old
  568.           name for the directory.
  569.  
  570.      read [ -p _✓p_✓r_✓o_✓m_✓p_✓t ] [ -e ] _✓v_✓a_✓r_✓i_✓a_✓b_✓l_✓e...
  571.           The prompt is printed if the -p option is specified and the stan-
  572.           dard input is a terminal.  Then a line is read from the standard
  573.           input.  The trailing newline is deleted from the line and the line
  574.           is split as described in the section on word splitting above, and
  575.           the pieces are assigned to the variables in order.  If there are
  576.           more pieces than variables, the remaining pieces (along with the
  577.           characters in IFS that separated them) are assigned to the last
  578.           variable.  If there are more variables than pieces, the remaining
  579.           variables are assigned the null string.
  580.  
  581.           The -e option causes any backslashes in the input to be treated
  582.           specially.  If a backslash is followed by a newline, the backslash
  583.           and the newline will be deleted.  If a backslash is followed by any
  584.           other character, the backslash will be deleted and the following
  585.           character will be treated as though it were not in IFS, even if it
  586.           is.
  587.  
  588.  
  589.      readonly _✓n_✓a_✓m_✓e...
  590.           The specified names are marked as read only, so that they cannot be
  591.           subsequently modified or unset.  _✓A_✓s_✓h allows the value of a variable
  592.           to be set at the same time it is marked read only by writing
  593.  
  594.               readonly name=value
  595.  
  596.           With no arguments the readonly command lists the names of all read
  597.           only variables.
  598.  
  599.      set [ { -_✓o_✓p_✓t_✓i_✓o_✓n_✓s | +_✓o_✓p_✓t_✓i_✓o_✓n_✓s | -- } ] _✓a_✓r_✓g...
  600.           The _✓s_✓e_✓t command performs three different functions.
  601.  
  602.           With no arguments, it lists the values of all shell variables.
  603.  
  604.           If options are given, it sets the specified option flags, or clears
  605.           them if the option flags are introduced with a + rather than a -.
  606.           Only the first argument to _✓s_✓e_✓t can contain options.  The possible
  607.           options are:
  608.  
  609.           -e  Causes the shell to exit when a command terminates with a
  610.               nonzero exit status, except when the exit status of the command
  611.               is explicitly tested.  The exit status of a command is con-
  612.               sidered to be explicitly tested if the command is used to con-
  613.               trol an _✓i_✓f, _✓e_✓l_✓i_✓f, _✓w_✓h_✓i_✓l_✓e, or _✓u_✓n_✓t_✓i_✓l; or if the command is the
  614.               left hand operand of an ``&&'' or ``||'' operator.
  615.  
  616.           -f  Turn off file name generation.
  617.  
  618.           -I  Cause the shell to ignore end of file conditions.  (This
  619.               doesn't apply when the shell a script sourced using the ``.''
  620.               command.)  The shell will in fact exit if it gets 50 eof's in a
  621.               row.
  622.  
  623.           -i  Make the shell interactive.  This causes the shell to prompt
  624.               for input, to trap interrupts, to ignore quit and terminate
  625.               signals, and to return to the main command loop rather than
  626.               exiting on error.
  627.  
  628.           -j  Turns on Berkeley job control, on systems that support it.
  629.               When the shell starts up, the -j is set by default if the -i
  630.               flag is set.
  631.  
  632.           -n  Causes the shell to read commands but not execute them.  (This
  633.               is marginally useful for checking the syntax of scripts.)
  634.  
  635.           -s  If this flag is set when the shell starts up, the shell reads
  636.               commands from its standard input.  The shell doesn't examine
  637.               the value of this flag any other time.
  638.  
  639.           -x  If this flag is set, the shell will print out each command
  640.               before executing it.
  641.  
  642.           -z  If this flag is set, the file name generation process may gen-
  643.               erate zero files.  If it is not set, then a pattern which does
  644.               not match any files will be replaced by a quoted version of the
  645.               pattern.
  646.  
  647.           The third use of the set command is to set the values of the
  648.           shell's positional parameters to the specified _✓a_✓r_✓g_✓s.  To change the
  649.           positional parameters without changing any options, use ``--'' as
  650.           the first argument to _✓s_✓e_✓t.  If no args are present, the set command
  651.           will leave the value of the positional parameters unchanged, so to
  652.           set the positional parameters to set of values that may be empty,
  653.           execute the command
  654.  
  655.               shift $#
  656.  
  657.           first to clear out the old values of the positional parameters.
  658.  
  659.      setvar _✓v_✓a_✓r_✓i_✓a_✓b_✓l_✓e _✓v_✓a_✓l_✓u_✓e
  660.           Assigns _✓v_✓a_✓l_✓u_✓e to _✓v_✓a_✓r_✓i_✓a_✓b_✓l_✓e.  (In general it is better to write
  661.           _✓v_✓a_✓r_✓i_✓a_✓b_✓l_✓e=_✓v_✓a_✓l_✓u_✓e rather than using _✓s_✓e_✓t_✓v_✓a_✓r.  _✓S_✓e_✓t_✓v_✓a_✓r is intended to be
  662.           used in functions that assign values to variables whose names are
  663.           passed as parameters.)
  664.  
  665.      shift [ _✓n ]
  666.           Shift the positional parameters _✓n times.  A shift sets the value of
  667.           $1 to the value of $2, the value of $2 to the value of $3, and so
  668.           on, decreasing the value of $# by one.  If there are zero posi-
  669.           tional parameters, shifting doesn't do anything.
  670.  
  671.      trap [ _✓a_✓c_✓t_✓i_✓o_✓n ] _✓s_✓i_✓g_✓n_✓a_✓l...
  672.           Cause the shell to parse and execute _✓a_✓c_✓t_✓i_✓o_✓n when any of the speci-
  673.           fied signals are received.  The signals are specified by signal
  674.           number.  _✓A_✓c_✓t_✓i_✓o_✓n may be null or omitted; the former causes the
  675.           specified signal to be ignored and the latter causes the default
  676.           action to be taken.  When the shell forks off a subshell, it resets
  677.           trapped (but not ignored) signals to the default action.  The trap
  678.           command has no effect on signals that were ignored on entry to the
  679.           shell.
  680.  
  681.      umask [ _✓m_✓a_✓s_✓k ]
  682.           Set the value of umask (see _✓u_✓m_✓a_✓s_✓k(2)) to the specified octal value.
  683.           If the argument is omitted, the umask value is printed.
  684.  
  685.      unset _✓n_✓a_✓m_✓e...
  686.           The specified variables and functions are unset and unexported.  If
  687.           a given name corresponds to both a variable and a function, both
  688.           the variable and the function are unset.
  689.  
  690.      wait [ _✓j_✓o_✓b ]
  691.           Wait for the specified job to complete and return the exit status
  692.           of the last process in the job.  If the argument is omitted, wait
  693.           for all jobs to complete and the return an exit status of zero.
  694.  
  695.    EXAMPLES
  696.      The following function redefines the _✓c_✓d command:
  697.  
  698.          cd() {
  699.              if bltin cd "$@"
  700.              thenif test -f .enter
  701.              then. .enter
  702.              elsereturn 0
  703.              fi
  704.              fi
  705.          }
  706.  
  707.      This function causes the file ``.enter'' to be read when you enter a
  708.      directory, if it exists.  The _✓b_✓l_✓t_✓i_✓n command is used to access the real
  709.      _✓c_✓d command.  The ``return 0'' ensures that the function will return an
  710.      exit status of zero if it successfully changes to a directory that does
  711.      not contain a ``.enter'' file.  Redefining existing commands is not
  712.      always a good idea, but this example shows that you can do it if you
  713.      want to.
  714.  
  715.      The suspend function distributed with _✓a_✓s_✓h looks like
  716.  
  717.          # Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
  718.          # This file is part of ash, which is distributed under the terms
  719.          # specified by the Ash General Public License.
  720.  
  721.          suspend() {
  722.              local -
  723.              set +j
  724.              kill -TSTP 0
  725.          }
  726.  
  727.      This turns off job control and then sends a stop signal to the current
  728.      process group, which suspends the shell.  (When job control is turned
  729.      on, the shell ignores the TSTP signal.)  Job control will be turned back
  730.      on when the function returns because ``-'' is local to the function.  As
  731.      an example of what _✓n_✓o_✓t to do, consider an earlier version of _✓s_✓u_✓s_✓p_✓e_✓n_✓d:
  732.  
  733.          suspend() {
  734.              suspend_flag=$-
  735.              set +j
  736.              kill -TSTP 0
  737.              set -$suspend_flag
  738.          }
  739.  
  740.      There are two problems with this.  First, suspend_flag is a global vari-
  741.      able rather than a local one, which will cause problems in the
  742.      (unlikely) circumstance that the user is using that variable for some
  743.      other purpose.  Second, consider what happens if shell received an
  744.      interrupt signal after it executes the first _✓s_✓e_✓t command but before it
  745.      executes the second one.  The interrupt signal will abort the shell
  746.      function, so that the second _✓s_✓e_✓t command will never be executed and job
  747.      control will be left off.  The first version of _✓s_✓u_✓s_✓p_✓e_✓n_✓d avoids this
  748.      problem by turning job control off only in a local copy of the shell
  749.      options.  The local copy of the shell options is discarded when the
  750.      function is terminated, no matter how it is terminated.
  751.  
  752.    HINTS
  753.      Shell variables can be used to provide abbreviations for things which
  754.      you type frequently.  For example, I set
  755.                export h=$HOME
  756.      in my .profile so that I can type the name of my home directory simply
  757.      by typing ``$h''.
  758.  
  759.      When writing shell procedures, try not to make assumptions about what is
  760.      imported from the environment.  Explicitly unset or initialize all vari-
  761.      ables, rather than assuming they will be unset.  If you use cd, it is a
  762.      good idea to unset CDPATH.
  763.  
  764.      People sometimes use ``<&-'' or ``>&-'' to provide no input to a command
  765.      or to discard the output of a command.  A better way to do this is to
  766.      redirect the input or output of the command to /dev/null.
  767.  
  768.      Word splitting and file name generation are performed by default, and
  769.      you have to explicitly use double quotes to suppress it.  This is back-
  770.      wards, but you can learn to live with it.  Just get in the habit of
  771.      writing double quotes around variable and command substitutions, and
  772.      omit them only when you really want word splitting and file name genera-
  773.      tion.  If you want word splitting but not file name generation, use the
  774.      -f option.
  775.  
  776.    AUTHORS
  777.      Kenneth Almquist
  778.  
  779.    SEE ALSO
  780.      echo(1), expr(1), line(1), pwd(1), true(1).
  781.  
  782.    BUGS
  783.      When command substitution occurs inside a here document, the commands
  784.      inside the here document are run with their standard input closed.  For
  785.      example, the following will not word because the standard input of the
  786.      _✓l_✓i_✓n_✓e command will be closed when the command is run:
  787.  
  788.          cat <<-!
  789.          Line 1: $(line)
  790.          Line 2: $(line)
  791.          !
  792.  
  793.  
  794.      Unsetting a function which is currently being executed may cause strange
  795.      behavior.
  796.  
  797.      The shell syntax allows a here document to be terminated by an end of
  798.      file as well as by a line containing the terminator word which follows
  799.      the ``<<''.  What this means is that if you mistype the terminator line,
  800.      the shell will silently swallow up the rest of your shell script and
  801.      stick it in the here document.
  802.  
  803.  
  804.  
  805.  
  806.  
  807.  
  808.  
  809.  
  810.  
  811.  
  812.  
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.